import sys

class Verbosity:
	"""Gives comfortable functionality to verbose/output informational text-data."""

	def __init__(self, verbose=False, prefix=""):
		"""Constructor, initalizes the verbosity-object.

		Parameter:
			boolean verbose Set the verbosity, true=text will be written, false=notTrue
			string prefix Prefix-String which will be prefixed to the text-data.
		"""

		self.setVerbosity(verbose)
		self.setPrefix(prefix)
	# End def

	def setVerbosity(self, verbose):
		"""Sets the verbosity for debugging-output. Should/can only be used
		with FUSE-option -f or -d.

		Parameter:
			bool verbose True to enable verbosity, false to be quiet.
		"""

		if type(verbose)!=bool: raise TypeError

		self.__verbose=verbose
	# End def

	def getVerbosity(self):
		"""Returns the currently set verbosity-setting."""

		return self.__verbose
	# End def

	def setPrefix(self, prefix):
		"""Sets the text which should be prefixed for the "out"-output."""

		if type(prefix)!=str: raise TypeError

		self.__prefix=prefix
	# End def

	def getPrefix(self):
		"""Returns the currently set prefix-text for the "out"-output."""

		return self.__prefix
	# End def

	def out(self, text):
		"""Writes/Outputs the text-string.

		Parameter:
			string text Text to be written.
		"""

		try:
			text=str(text)
		except:
			pass
		# End try/except

		if self.getVerbosity():
			if type(text)!=str: raise TypeError

			print self.getPrefix(), text
			sys.stdout.flush()
		# End if
	# End def

# End class
